<?php

namespace App\Traits\Relation;

use App\Models\Courier;
use App\Models\ExpressCompany;
use App\Models\OrderInfo;
use App\Models\Service;
use App\Models\ShipperInformation;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
 * 用于定义订单和其他模型的关系
 *
 * @package App\Traits\Relation
 * Date: 2018/05/28
 * @author Tenny
 */
trait OrderRelation
{
    /**
     * 获取订单负责的快递员
     *
     * Date: 2018/06/15
     * @author Tenny
     * @return Relation
     */
    public function courier()
    {
        return $this->hasOne(Courier::class, 'id', 'courier_id');
    }

    /**
     * 获取订单所属服务站
     *
     * Date: 2018/06/15
     * @author Tenny
     * @return Relation
     */
    public function service()
    {
        return $this->hasOne(Service::class, 'id', 'service_id');
    }

    /**
     * 获取订单的快递公司
     *
     * Date: 2018/06/15
     * @author Tenny
     * @return Relation
     */
    public function express()
    {
        return $this->hasOne(ExpressCompany::class, 'id', 'express_id');
    }

    /**
     * 获取订单的收发件信息
     *
     * Date: 2018/06/15
     * @author Tenny
     * @return Relation
     */
    public function info()
    {
        return $this->hasOne(OrderInfo::class, 'order_id', 'id');
    }

    /**
     * 获取订单的收发件信息
     *
     * Date: 2018/06/15
     * @author Tenny
     * @return Relation
     */
    public function shipper()
    {
        return $this->hasOne(ShipperInformation::class, 'id', 'shipper_id');
    }
}
